package com.longrise.android.byjk.plugins.tabthird.personal;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.android.byjk.model.UserInfor;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;
import com.longrise.common.datasource.remote.LoadDataManager;

import static com.longrise.common.utils.AppUtil.showToast;

/**
 * Created by Administrator on 2018/3/6.
 * 更换背景---高级详情presenter
 */

public class ChangeSeniorWallDeatilPresenter extends ChangeSeniorWallDetailContract.Presenter{


    @Override
    protected void init() {

    }

    @Override
    public void getBackgroundWallData(String id) {
        String usersfzh = UserInfor.getInstance().getUsersfzh();
        String userid = UserInfor.getInstance().getUserid();
        EntityBean bean = new EntityBean();
        bean.set("id", id);
        bean.set("userid ", userid);
        bean.set("cardno", usersfzh);
        EntityBean fbean = new EntityBean();
        fbean.set("bean", bean);
        LoadDataManager.getInstance().callService2("", UrlConstants.BaseUrl,
                "bbt_vip_sCostAllRecordBygoodstype", fbean, new LoadDataManager.OnRequestCallListener2() {
                    @Override
                    public void onSuccess(String key, String service, Object result) {
                        EntityBean bean = (EntityBean) result;
                        int resultstate = bean.getInt("resultstate");
                        if (resultstate == 1){
                            mView.refreshWallData(bean);
                        }
                    }

                    @Override
                    public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

                    }

                    @Override
                    public void onFinished(String key, String service) {
                        mView.setRefreshing(false);
                    }
                });
    }


    @Override
    public void getNormalWallData() {
        String usersfzh = UserInfor.getInstance().getUsersfzh();
        String userid = UserInfor.getInstance().getUserid();
        EntityBean bean = new EntityBean();
        bean.set("userid ", userid);
        bean.set("cardno", usersfzh);
        EntityBean fbean = new EntityBean();
        fbean.set("bean", bean);
        LoadDataManager.getInstance().callService2("", UrlConstants.BaseUrl,
                "bbt_vip_sCostAllRecordBygoodsOrdinary", fbean, new LoadDataManager.OnRequestCallListener2() {
                    @Override
                    public void onSuccess(String key, String service, Object result) {
                        EntityBean bean = (EntityBean) result;
                        int resultstate = bean.getInt("resultstate");
                        if (resultstate == 1){
                            mView.refreshWallData(bean);
                        }
                    }

                    @Override
                    public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

                    }

                    @Override
                    public void onFinished(String key, String service) {
                        mView.setRefreshing(false);
                    }
                });
    }

    /**
     * 换肤
     */
    @Override
    public void toChangeSkin(String goodsid) {
        EntityBean bean = new EntityBean();
        bean.set("userid", UserInfor.getInstance().getUserid());
        bean.set("cardno", UserInfor.getInstance().getUsersfzh());
        bean.set("skinid", goodsid);
        EntityBean fbean = new EntityBean();
        fbean.set("bean", bean);
        mView.showLoadingDialog();
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl, "bbt_vip_uVIPstateBySkinidNew", fbean, new LoadDataManager.OnRequestCallListener2() {
            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    EntityBean bean = (EntityBean) result;
                    String resultdesc = bean.getString("resultdesc");
                    int value = (Integer) bean.get("resultstate");
                    if (value == 1) {
//                        onRefresh();
                        showToast("更换成功");
                        mView.responseChangeSkin();
                    } else {
                        showToast(resultdesc);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished(String key, String service) {
                mView.dismissLoadingDialog();
            }

            @Override
            public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

            }

        });
    }
}
